package com.acme.bankapp.server;

import com.acme.bankapp.domain.Bank;
import java.io.IOException;

/**
 * Created by splash on 21.11.2014.
 */
public class BankServerProxy {

    private BankServerTransport bankServerTransport;

    public BankServerProxy(BankServerTransport bankServerTransport) {
        this.bankServerTransport = bankServerTransport;
    }

    public BankServerTransport getBankServerTransport() {
        return bankServerTransport;
    }

    public String loadCommand() throws IOException {
        return bankServerTransport.readLine().toLowerCase();
    }

    public void processCommand (Bank bank, String command) throws IOException {
        switch (command) {
            case "info":
                if (bank.getClients().size() != 0) {
                    BankServerService.info(bank, bankServerTransport);
                } else {
                    bankServerTransport.writeLine("Bank is empty");
                    bankServerTransport.writeLine("eof");
                }
                break;
            case "addnew":
                BankServerService.addNewClient(bank, bankServerTransport);
                break;
            case "exit":
                System.out.println("User has finished session. Closing connection.");
                BankServerService.exit(bankServerTransport);
                break;
            default:
                BankServerService.incorrectCommand(bankServerTransport);
        }
    }

}
